home *** CD-ROM | disk | FTP | other *** search
- #include <graphics libraries.h>
- #include <graphics toolbox.h>
- #include <qd library.h>
- #include "AppInterface.h"
- #include "TileProtos.h"
- #include "TileConstants.h"
-
- MenuHandle gAppMenuHandle;
- WindowPtr gWindPtr;
-
- //---------------------------------------
- // Tile globals
-
- extern Boolean gContRedraw, gKeepClosed; // State Booleans
- extern long gSymmetry;
-
-
- /* Called by the Shell at startup time */
- Boolean AppInit(void)
- {
- Boolean AOK;
-
- AOK = TileInit();
- if(AOK && gKeepClosed)
- AttachConstraints();
- return AOK;
- }
-
- /* Called when the shell receives an Activate event. */
- void AppActivate(WindowPtr wind, Boolean activate)
- {
- }
-
- /* Called when a window needs updating. BeginUpdate() has already been called, and the
- port is set to the appropriate window */
- void AppUpdate(EventRecord *event)
- {
- TileUpdate();
- }
-
- /* Called when the shell recieves a null event. */
- void AppIdle(EventRecord *Event)
- {
- }
-
- /* Called when there is a click in the content of a window. The port is already set to
- the window, and thePt is in local coords. */
- void AppClick(Point thePt, WindowPtr wind, Boolean doubleClick, EventRecord *theEvent)
- {
- gxPoint clickPt;
-
- ShortPointToFixed(&thePt, &clickPt);
-
- if(TileClick(&clickPt, theEvent->modifiers & optionKey))
- InvalRect(&wind->portRect);
-
- }
-
- /* Called when there is a click in the grow region. Just grows the window, resetting
- necessary shapes */
- void AppGrowWindow(WindowPtr wind, Point where, Rect *desk)
- {
- Rect limits;
- long size;
-
- /* Set up size limits */
- limits.top = limits.left = 72; /* One inch minimum */
-
- // Limit to something reasonable
- limits.right = 600;
- limits.bottom = 450;
-
- /* Let the user grow the window */
- size = GrowWindow(wind, where, &limits);
-
- // If the size changed, then size the window
- if(size != 0)
- {
- short hSize, vSize;
-
- SetPort(wind);
-
- /* OK, size it, but first make sure that the size is within limits (users
- can hold down the command key to bypass the limit, but we won't let 'em).
- Note that we subtract 1 from the limits to account for the window frame */
- hSize = LoWord(size);
- vSize = HiWord(size);
- if(hSize > limits.right - 1) hSize = limits.right - 1;
- if(vSize > limits.bottom - 1) vSize = limits.bottom - 1;
-
- if(ChangeWindowSize(gWindPtr, hSize, vSize) == true)
- InvalRect(&wind->portRect);
- else
- SysBeep(10);
- }
- }
-
- /* Called when the user clicks in the zoom box of a window. */
- void AppZoomWindow(WindowPtr wind, short zoomDir)
- {
- }
-
- /* Called when there is a click in the menu bar, before the menu is shown. This is
- the app's opportunity to enable and disable menu items. */
- void AppAdjustMenus()
- {
- CheckItem(gAppMenuHandle, iContRedraw, gContRedraw);
- CheckItem(gAppMenuHandle, iConstrain, gKeepClosed);
- }
-
- /* called when a menu other than Apple, File, or Edit is used. */
- void AppMenu(short id, short item)
- {
- if(id == kTileMenuID)
- {
- switch(item)
- {
- case iContRedraw:
- gContRedraw = !gContRedraw;
- break;
-
- case iConstrain:
- gKeepClosed = !gKeepClosed;
- if(gKeepClosed)
- AttachConstraints();
- InvalRect(&gWindPtr->portRect);
- break;
-
- case iResetTile:
- DefaultTileAndPattern();
- InvalRect(&gWindPtr->portRect);
- break;
-
- // A symmetry group was picked
- default:
- if(item != gSymmetry)
- {
- CheckItem(gAppMenuHandle, gSymmetry, false);
- ChangeSymmetry(gSymmetry, (long)item);
- CheckItem(gAppMenuHandle, gSymmetry, true);
- InvalRect(&gWindPtr->portRect);
- }
- break;
- }
- }
- }
-
-
- // Called when the user selects "New" from the File menu.
- void AppNew(void)
- {
- ShowWindow(gWindPtr);
- }
-
- /* Called when the user selects "Open" from the File menu. */
- void AppOpen(void)
- {
- ShowWindow(gWindPtr);
- }
-
-
- /* Called when the user selects "Close" from the File menu or clicks the close box
- of a window. */
- Boolean AppClose(void)
- {
- /* returns false if the user cancels the save */
- HideWindow(gWindPtr);
- return true;
- }
-
- /* Called when the user selects "Save" from the File menu. */
- Boolean AppSave(void)
- {
- /* returns false if the user cancels the save */
- return true;
- }
-
- /* Called when the user selects "Save As..." from the File menu. */
- Boolean AppSaveAs(void)
- {
- /* returns false if the user cancels the save */
- return true;
- }
-
- /* Called when the user selects "Page Setup..." from the File menu. */
- void AppPageSetup(void)
- {
- }
-
- /* Called when the user selects "Print..." from the File menu. */
- void AppPrint(void)
- {
- }
-
- /* Called when the user selects "Undo" from the Edit menu. */
- void AppUndo(void)
- {
- }
-
- /* Called when the user selects "Cut" from the Edit menu. */
- void AppCut(void)
- {
- }
-
- /* Called when the user selects "Copy" from the Edit menu. */
- OSErr AppCopy(void)
- {
- return noErr;
- }
-
- /* Called when the user selects "Paste" from the Edit menu. */
- void AppPaste(void)
- {
- }
-
- /* Called when the user selects "Clear" from the Edit menu. */
- void AppClear(void)
- {
- }
-
- /* Called when the user chooses "Quit" from the File menu. If the user cancels
- the save it returns false, otherwise it returns true and the shell quits */
- Boolean AppQuit(void)
- {
- /* returns false if the user cancels the save at any point */
- return true;
- }
-
- /* Called when the shell is about to quit, just deallocates memory. */
- void AppCleanUp(void)
- {
- TileQuit();
- }
-